package flc.ast.fragment;

import android.graphics.Color;

import androidx.fragment.app.Fragment;

import android.view.View;

import com.blankj.utilcode.util.FragmentUtils;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.databinding.FragmentTimerBinding;
import flc.ast.fragment.timer.SecondFragment;
import flc.ast.fragment.timer.TimeFragment;
import flc.ast.utils.AudioPlayerImpl;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link TimerFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class TimerFragment extends BaseNoModelFragment<FragmentTimerBinding> {

    private List<Fragment> mFragmentList;
    private TimeFragment timeFragment;
    private SecondFragment secondFragment;

    @Override
    protected int onCreate() {
        return R.layout.fragment_timer;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);

        mDataBinding.tvTimer.setOnClickListener(this);
        mDataBinding.tvSecondWatch.setOnClickListener(this);

        mFragmentList = new ArrayList<>();
        timeFragment = new TimeFragment();
        secondFragment = new SecondFragment();
        mFragmentList.add(timeFragment);
        mFragmentList.add(secondFragment);
        FragmentUtils.add(getChildFragmentManager(), mFragmentList, R.id.flFragment, 0);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvTimer://计时器
                clearSelection();
                mDataBinding.tvTimer.setBackgroundResource(R.drawable.timer_sel);
                mDataBinding.tvTimer.setTextColor(Color.parseColor("#000000"));
                FragmentUtils.showHide(0, mFragmentList);
                mDataBinding.llContent.setBackgroundResource(R.drawable.abj1);
                break;
            case R.id.tvSecondWatch://秒表
                clearSelection();
                mDataBinding.tvSecondWatch.setBackgroundResource(R.drawable.timer_sel);
                mDataBinding.tvSecondWatch.setTextColor(Color.parseColor("#000000"));
                FragmentUtils.showHide(1, mFragmentList);
                mDataBinding.llContent.setBackgroundResource(R.drawable.abj2);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void clearSelection() {
        mDataBinding.tvTimer.setBackground(null);
        mDataBinding.tvTimer.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvSecondWatch.setBackground(null);
        mDataBinding.tvSecondWatch.setTextColor(Color.parseColor("#B2C1CF"));
    }

}